#include "ParticleNode.h"
namespace FireCloud{
ParticleNode::ParticleNode(GLvector speed,GLcolor start_color,
GLcolor end_color,GLfloat start_size,
GLfloat end_size,GLuint life){
	m_pos.x = 0;m_pos.y = 0;m_pos.z = 0;
	m_speed = speed;
	m_start_color = start_color;
	m_end_color = end_color;
	m_start_size = start_size;
	m_end_size = end_size;
	m_life = life;
	m_age = 0;
	m_diff_size = m_end_size-m_start_size;
	ParticleTools::diff_glcolor(m_start_color,m_end_color,m_diff_color);
}
GLboolean ParticleNode::draw(GLvector a){
	static GLfloat pos_array[] = {1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,0.0f,0.0f,-1.0f,0.0f,0.0f,0.0f};
	static GLubyte face_array[] = {3,0,1,0,2,1,3,1,2,3,0,2};
	GLfloat age_div_life = (GLfloat)m_age/(GLfloat)m_life;
	GLcolor cur_color;
	GLfloat cur_size = ParticleTools::ratio_glfloat(m_start_size,m_diff_size,age_div_life);
	ParticleTools::ratio_glcolor(m_start_color,m_diff_color,cur_color,age_div_life);
	ParticleTools::add_glvector(m_pos,m_speed);
	ParticleTools::add_glvector(m_speed,a);
	glPushMatrix();
	glTranslatef(m_pos.x,m_pos.y,m_pos.z);
	glScalef(cur_size,cur_size,cur_size);
	glColor4f(cur_color.r,cur_color.g,cur_color.b,cur_color.a);
	glVertexPointer(3,GL_FLOAT,0,pos_array);
	glDrawElements(GL_TRIANGLES,12,GL_UNSIGNED_BYTE,face_array);
	glPopMatrix();
	++m_age;
	if(m_age>m_life){
		return GL_TRUE;
	}else{
		return GL_FALSE;
	}
}
}
